package com.zyp.jobseeker.enums;

/**
 * 用户角色枚举
 */
public enum UserRole {
    STUDENT(1, "学生"),
    ENTERPRISE(2, "企业"),
    ADMIN(3, "管理员");

    private final int code;
    private final String desc;

    UserRole(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据code获取对应的枚举值
     */
    public static UserRole getByCode(int code) {
        System.out.println("[UserRole Enum] 🔍 查找角色 - 请求代码: " + code);
        for (UserRole role : UserRole.values()) {
            System.out.println("[UserRole Enum] 🆔 检查角色 - 代码: " + role.getCode() + ", 名称: " + role.name());
            if (role.getCode() == code) {
                System.out.println("[UserRole Enum] ✅ 匹配成功 - 代码: " + code + " -> " + role.getDesc());
                return role;
            }
        }
        System.out.println("[UserRole Enum] ❌ 匹配失败 - 无效代码: " + code);
        throw new IllegalArgumentException("无效的用户角色代码: " + code);
    }
}
